--#include "data\config\fuben\AllDayCfg.lua" once
--#include "data\functions\Common\RankMgr.lua" once 		--排行榜管理
----#include "data\functions\Activity\OnOpenServerUniversal.lua"   once         --开服全民活动

--勇闯魔巢 原（闯天关）

--获取副本信息
function AllDayGetInfo(sysarg, packet)
	local Label = packet 
	if(type(packet) ~= 'number')then
		Label = DataPack.readByte(packet)
	end
	if(AllDayCfg[Label] == nil)then
		return
	end
	--print("Label ="..Label)
	local npack = DataPack.allocPacket(sysarg,LogicCmd.activitySys.sysId, LogicCmd.activitySys.sub.sPathMonsterNestInfo)   
	if npack == nil then return end
	local startTime, completeCount, TableHistory = CheckAllDayData(sysarg, Label, 1)
	----------print(startTime, completeCount, TableHistory )
	DataPack.writeByte(npack, Label)
	DataPack.writeByte(npack, #AllDayCfg[Label].Checkpoint)	--通关数据
	for k=1, #AllDayCfg[Label].Checkpoint do
		local startTime, completeTime, completeCount = 0, 0, 0
		local star = 0
		if(TableHistory[Label][k] ~= nil)then
			startTime = TableHistory[Label][k].startTime or 0
			completeTime = TableHistory[Label][k].completeTime or 0
			completeCount = TableHistory[Label][k].completeCount or 0
			star = 0
			if completeTime > 0 then
				star = 1
				for k,v in pairs(AllDayCfg[Label].Star)do
					if(0 < completeTime and completeTime <= v)then
						star = k
					end
				end
			end
		end	
		--print("star = "..star)
		--print("completeCount = "..completeCount)
		--print("startTime = "..startTime)
		DataPack.writeByte(npack, star)
		DataPack.writeByte(npack, completeCount)
		DataPack.writeInt(npack, startTime)
		
		----print("completeTime,completeCount,startTime",completeTime.." "..completeCount.." "..startTime)
	end
	local ChapterHistory = CheckAllDayChapterData(sysarg, Label)	
	local cfg = ChapterHistory[Label].StarAward
	DataPack.writeByte(npack, #AllDayCfg[Label].AwardCfg)	--累积星信息
	for k,v in pairs(AllDayCfg[Label].AwardCfg)do
		--print("cfg[k] = ".. (cfg[k] or 0))
		DataPack.writeByte(npack, cfg[k] or 0)
		--print("Star",cfg[k])
	end
	--[[	--屏蔽宝箱信息
	local SurplusTime = ChapterHistory[Label].Package[1] or System.getCurrMiniTime()
	local SurplusCount = ChapterHistory[Label].Package[2] or 0	
	SurplusTime = SurplusTime + AllDayCfg[Label].Package.SurplusTime - System.getCurrMiniTime()
	if(SurplusTime < 0)then
		SurplusTime = 0
	end
	DataPack.writeByte(npack, SurplusCount)				--特惠礼包
	DataPack.writeInt(npack, SurplusTime)
	DataPack.writeByte(npack, #AllDayCfg[Label].Chest)	--宝箱信息
	local ChestCfg = ChapterHistory[Label].Chest
	for k,v in pairs(AllDayCfg[Label].Chest)do
		DataPack.writeByte(npack, ChestCfg[k] or 0)
		--------print("Chest",ChestCfg[k])
	end
	]]
	--print("SurplusTime,ChapterHistory[Label].Package[1] "..SurplusTime,ChapterHistory[Label].Package[1])
	DataPack.flush(npack)
	--------print("获取副本信息")
end

--先检查够不够
function AllDayLogicCheck(sysarg, consumes, nCount)
    --消耗检查
	return CheckConsumeCond(sysarg, consumes, nCount)
end

--请求进入副本
function AllDaySweep(sysarg, packet)
	local Label = DataPack.readByte(packet)
	local index = DataPack.readByte(packet)
	local count = DataPack.readByte(packet)
	if(AllDayCfg[Label] == nil)then
		return ----print(Label)
	end
	local cfg = AllDayCfg[Label].Checkpoint[index]
	if(cfg == nil)then
		return ----print(cfg)
	end

	--local nLevel = Actor.getIntProperty(sysarg, PROP_CREATURE_LEVEL)	
	local nNeedLv = cfg.Level
	if not Actor.checkActorLevel(sysarg, nNeedLv, 0) then
		return Actor.sendTipmsg( sysarg, string.format(Lang.ScriptTips.PathMonsterNest018, nNeedLv), ttFlyTip )
	end	
	
	local startTime, completeCount, TableHistory, completeTime = CheckAllDayData(sysarg, Label, index)

	local star = 0
	if completeTime > 0 then
		star = 1
		for k,v in pairs(AllDayCfg[Label].Star)do
			if(0 < completeTime and completeTime <= v)then
				star = k
			end
		end
	end

	local len = #AllDayCfg[Label].Star
	if star ~= len then
		return Actor.sendTipmsg( sysarg, string.format(Lang.ScriptTips.PathMonsterNest016, len), ttFlyTip )
	end

	if(cfg.Count <= completeCount)then
		return Actor.sendTipmsg( sysarg, Lang.ScriptTips.PathMonsterNest002, ttFlyTip )
	end	
	if(cfg.Count < completeCount + count)then
		return Actor.sendTipmsg( sysarg, string.format(Lang.ScriptTips.PathMonsterNest017, count), ttFlyTip )
	end

	if count ~= 1 then
		return Actor.sendTipmsg( sysarg, string.format(Lang.ScriptTips.PathMonsterNest019, count), ttFlyTip )
	end
	
	local awards = AllDayCfg[Label].Checkpoint[index].Awards[len].Award
	if(awards == nil)then
		return
	end
	awardsNew = GetAwardsByRate(awards, count)
	local logId, logStr = LogIds.PathMonsterNestLogId, Lang.LogTips.LogAllDay	--修改
	local actorId = Actor.getActorId(sysarg)
	if Awards.CheckBagGridCount(sysarg, awardsNew) ~= true then
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.COM0015, ttFlyTip)
	else
		if(AllDayLogicCheck(sysarg, cfg.sweepconsume, count) ~= true)then
			return ----print("AllDayLogicCheck")
		end
		if not DoConsumeCond( sysarg, cfg.sweepconsume, count, LogIds.PathMonsterNestLogId, Lang.LogTips.LogAllDay ) then
			return
		end


			 
		Actor.triggerQuestEvent(sysarg, 45, 2, count)
		 		
		SetAllDayCount(sysarg, Label, index, count)	--保存次数

		for idx = 1, count do
			Actor.triggerAchieveEvent(sysarg, 35, AllDayCfg[Label].Checkpoint[index].EnterPos[1])
		end

		--[[
		Awards.Give(sysarg, awardsNew, logId, logStr)	

		local npack = DataPack.allocPacket(sysarg,LogicCmd.activitySys.sysId, LogicCmd.activitySys.sub.sPathMonsterNestSweep)    
		if npack == nil then return end
		DataPack.writeByte(npack, Label)   	 
		DataPack.writeByte(npack, index)	
		DataPack.writeByte(npack, count)  
		DataPack.writeByte(npack, 1) 	
		DataPack.flush(npack)
		]]

		local actorVar = Actor.getDyanmicVar(sysarg)
		if(actorVar.AllDayDyanmicVar == nil)then
			actorVar.AllDayDyanmicVar = {}
		end	
		actorVar.AllDayDyanmicVar[1] = Label
		actorVar.AllDayDyanmicVar[2] = index
		actorVar.AllDayDyanmicVar[4] = star

		AllDaySendCopyEnd(sysarg, Label, index, star, 1)
	end	

end

--请求进入副本
function AllDayEnterScene(sysarg, packet, idx)
	----[[ --没有镖车
	if Actor.getIsDartFlag(sysarg) then
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.EscortTips010, ttFlyTip)
		return
	end
	--]]
	------print("AllDayEnterScene")

	local actorVar = Actor.getDyanmicVar(sysarg)
	actorVar.AllDayDonotChangeDVar = nil

	local sVar = Actor.getStaticVar(sysarg)
	sVar.AllDayDyanmicVar = nil

	local Label = packet 
	local index = idx
	if(type(packet) ~= 'number')then
		Label = DataPack.readByte(packet)
		index = DataPack.readByte(packet)
	end
	if(AllDayCfg[Label] == nil)then
		return ----print(Label)
	end
	local cfg = AllDayCfg[Label].Checkpoint[index]
	if(cfg == nil)then
		return ----print(cfg)
	end
	
	--[[ --没有团队副本
	--是否有团队副本
	if Actor.hasState(sysarg,esStateTeamFuben) then
		Actor.sendTipmsg(sysarg, Lang.Script.EscortTips022, ttFlyTip)
		return false  
	end		
	]]
	
	--[[ --没有镖车
	--是否在押运状态
	if Actor.getIsDartFlag(sysarg) then
        Actor.sendTipmsg(sysarg,Lang.Script.EscortTips006,ttFlyTip)
        return false 
	end
	]]

	--[[ -- 没有团队副本
	--是否在副本中
	if Actor.getFubenId(sysarg) > 0 then
		Actor.sendTipmsg(sysarg,Lang.Script.TeamFuben003,ttFlyTip)		
		return ----print("getFubenId")
	end
	]]
	
	local startTime, completeCount, TableHistory = CheckAllDayData(sysarg, Label, index)
	if(cfg.Count <= completeCount)then
		return Actor.sendTipmsg( sysarg, Lang.ScriptTips.PathMonsterNest002, ttFlyTip )
	end	
	
	if(1 < index)then	--不能跳关卡
		local startTime, completeCount, TableHistory, completeTime = CheckAllDayData(sysarg, Label, index-1)
		if(completeTime == 0)then
			Actor.sendTipmsg( sysarg, Lang.ScriptTips.PathMonsterNest009, ttFlyTip )
			return
		end
	else
		if(1 < Label)then
			local nLen = #AllDayCfg[Label-1].Checkpoint
			local startTime, completeCount, TableHistory, completeTime = CheckAllDayData(sysarg, Label-1, nLen)
			--print(Label-1,nLen)
			if(completeTime == 0)then
				return
			end			
		end
	end
	
	--local nLevel = Actor.getIntProperty(sysarg, PROP_CREATURE_LEVEL)	
	local nNeedLv = cfg.Level
	if not Actor.checkActorLevel(sysarg, nNeedLv, 0) then
		return Actor.sendTipmsg( sysarg, string.format(Lang.ScriptTips.PathMonsterNest003, nNeedLv), ttFlyTip )
	end	
	
	if(AllDayLogicCheck(sysarg, cfg.consume, 1) ~= true)then
		return ----print("AllDayLogicCheck")
	end

	if not DoConsumeCond( sysarg, cfg.consume, 1, LogIds.PathMonsterNestLogId, Lang.LogTips.LogAllDay ) then
		return
	end
		 
	if(StartEnterFb(sysarg,  cfg.FbId) ~=true)then
		return
	end

	Actor.triggerQuestEvent(sysarg, 45, 2, 1)
	 
	--Actor.enterScene(sysarg,unpack(cfg.EnterPos))
	AllDayCreateMonsters(sysarg, Label, index)	
	CheckAllDayData(sysarg, Label, index, System.getCurrMiniTime())	
	OpenAllDayRightPanel(sysarg, Label, index)	
	SetAllDayCount(sysarg, Label, index)	--保存次数
	--副本超时	
	local lastTime = AllDayCfg[Label].Star[1]
	Actor.unregScriptCallback(sysarg, "AllDaySendCopyEnd")	
	Actor.regScriptTimer(sysarg, 0, lastTime*1000, lastTime*1000 , 1, "AllDaySendCopyEnd",Label,index,0,0)
	----print("请求进入副本")
end

--计算星星
function AllDayGetCrossStar(Label, nTime)
	local star = 0
	for k,v in pairs(AllDayCfg[Label].Star)do
		if(nTime ~= 0 and nTime <= v)then
			star = k
		end
	end	
	return star
end

--计算某一章的星星
function getAllDayChapterStar(sysarg, Label)
	local startTime, completeCount, TableHistory = CheckAllDayData(sysarg, 1, 1)
	local ChapterStar = 0		--某章的星星
	for k,v in pairs(TableHistory[Label])do
		local completeTime = v.completeTime or 0
		local star = AllDayGetCrossStar(k, completeTime)
		ChapterStar = ChapterStar + star
	end
	return ChapterStar
end

--计算总星星保存星星
function AllDayGetSaveAward(sysarg)
	local startTime, completeCount, TableHistory = CheckAllDayData(sysarg, 1, 1)
	local AllStar = 0				--总的星星
	for k,v in pairs(AllDayCfg)do
		local ChapterStar = 0		--某章的星星
		for i,j in pairs(v.Checkpoint)do
			local startTime, completeTime, completeCount = 0, 0, 0
			if(TableHistory[k] ~=nil and TableHistory[k][i] ~= nil)then
				completeTime = TableHistory[k][i].completeTime or 0
				local star = AllDayGetCrossStar(k, completeTime)
				AllStar = AllStar + star
				ChapterStar = ChapterStar + star
			end
		end
	end
	local actorId = Actor.getActorId(sysarg)
	gRankMgr_SetRank(actorId, RANK_DEFINE_ALLDAY, AllStar )
	gRankMgr_Save(RANK_DEFINE_ALLDAY)			--记得保存排行榜	
end

--奖励领取
function AllDayNormalAward(sysarg, packet)
	local factor = DataPack.readByte(packet)

	local actorVar = Actor.getDyanmicVar(sysarg)
	if(actorVar.AllDayDyanmicVar == nil)then
		actorVar.AllDayDyanmicVar = {}
	end	
	local Label = actorVar.AllDayDyanmicVar[1]
	local index = actorVar.AllDayDyanmicVar[2]
	local star = actorVar.AllDayDyanmicVar[4]
	
	if Label and index and star then
		if not AllDayCfg[Label] then
			return
		end
		if not AllDayCfg[Label].Checkpoint then
			return
		end
		if not AllDayCfg[Label].Checkpoint[index] then
			return
		end
		if factor and factor > 0 then
			local timesConsumeRate = 1
			if Actor.getIntProperty(sysarg, PROP_ACTOR_SUPER_VIP) > 0 then
				timesConsumeRate = SuperVipConfig.allDayDoubleCrossAwardRate
			end
			if not AllDayCfg[Label].Checkpoint[index].timesconsume then
				return
			end
			if (AllDayLogicCheck(sysarg, AllDayCfg[Label].Checkpoint[index].timesconsume, timesConsumeRate) ~= true)then
				return ----print("AllDayLogicCheck")
			end

			if not DoConsumeCond( sysarg, AllDayCfg[Label].Checkpoint[index].timesconsume, timesConsumeRate, LogIds.PathMonsterNestLogId, Lang.LogTips.LogAllDay ) then
				return
			end
		end
		actorVar.AllDayDyanmicVar = nil
		AllDayGetCrossAward(sysarg, Label, index, star, factor)	
		AllDayGetInfo(sysarg, Label)

		AllDayExit(sysarg)
	else
		Actor.sendTipmsg( sysarg, Lang.ScriptTips.PathMonsterNest020, ttFlyTip )
	end
end

--通关奖励
function AllDayGetCrossAward(sysarg, Label, index, nStar, isfactor)
	if not AllDayCfg[Label] then
		return
	end
	if not AllDayCfg[Label].Checkpoint then
		return
	end
	if not AllDayCfg[Label].Checkpoint[index] then
		return
	end
	if not AllDayCfg[Label].Checkpoint[index].Awards then
		return
	end
	if not AllDayCfg[Label].Checkpoint[index].Awards[nStar] then
		return
	end
	local awards = AllDayCfg[Label].Checkpoint[index].Awards[nStar].Award
	if(awards == nil)then
		return
	end
	if isfactor and isfactor > 0 then
		awards = GetAwardsByRate( awards, AllDayCfg[Label].Checkpoint[index].timesfactor ) 
	end
	local logId, logStr = LogIds.PathMonsterNestLogId, Lang.LogTips.LogAllDay	--修改
	local actorId = Actor.getActorId(sysarg)
	if Awards.CheckBagGridCount(sysarg, awards) ~= true then
		local title = Lang.ScriptTips.PathMonsterNest014
		local content = Lang.ScriptTips.PathMonsterNest015
		Awards.GiveToMailById(actorId, awards, title, content, logId, logStr) 
	else
		Awards.Give(sysarg, awards, logId, logStr)		
	end	
	AllDayGetSaveAward(sysarg)	
	--print("通关奖励,AllStar",AllStar)
end

function CurChapterStars(sysarg, Label)
	local totalStar = 0
	local startTime, completeCount, TableHistory = CheckAllDayData(sysarg, Label, 1)
	for k=1, #AllDayCfg[Label].Checkpoint do
		local startTime, completeTime, completeCount = 0, 0, 0
		local star = 0
		if(TableHistory[Label][k] ~= nil)then
			startTime = TableHistory[Label][k].startTime or 0
			completeTime = TableHistory[Label][k].completeTime or 0
			completeCount = TableHistory[Label][k].completeCount or 0
			star = 0
			if completeTime > 0 then
				star = 1
				for k,v in pairs(AllDayCfg[Label].Star)do
					if(0 < completeTime and completeTime <= v)then
						star = k
					end
				end
			end
		end	
		totalStar = star + totalStar
	end
	return totalStar
end

--领取星奖励	记得条件检测
function AllDayGetAward(sysarg, packet, idx)
	local Label = packet 
	local index = idx
	if(type(packet) ~= 'number')then
		Label = DataPack.readByte(packet)
		index = DataPack.readByte(packet)
	end
	if(AllDayCfg[Label] == nil)then
		return
	end
	local TableHistory = CheckAllDayChapterData(sysarg, Label)	
	if(TableHistory[Label].StarAward[index] ~= nil)then	--领过奖励了
		return Actor.sendTipmsg( sysarg, Lang.ScriptTips.PathMonsterNest004, ttFlyTip )
	end
	local cfg = AllDayCfg[Label].AwardCfg[index]
	if(cfg == nil)then
		return
	end

	--我的数据
	--[[
	local myStar = 0
	local rankName = RankList[RANK_DEFINE_ALLDAY].strName
	local ranking = Ranking.getRanking( rankName )
	if (ranking ~= nil) then
		local myId = Actor.getActorId(sysarg)
		local item = Ranking.getItemPtrFromId( ranking, myId)
		if item then
			myStar = Ranking.getPoint(item) or 0
		end	
	end	
	]]
	local myStar = CurChapterStars(sysarg, Label)
	if(myStar < cfg.myStar)then
		--print("myStar",myStar)
		return Actor.sendTipmsg( sysarg, Lang.ScriptTips.PathMonsterNest005, ttFlyTip )
	end
	
	local awards = cfg.Award
	if(awards == nil)then
		return
	end
	local logId, logStr = LogIds.PathMonsterNestLogId, Lang.LogTips.LogAllDay	--修改
	if Awards.CheckBagGridCount(sysarg, awards) ~= true then
		--Actor.sendTipmsg(sysarg, Lang.ScriptTips.COM0015, ttFlyTip)
		return 
	end	
	Awards.Give(sysarg, awards, logId, logStr)
	local sysVar = Actor.getStaticVar(sysarg)	
	TableHistory[Label].StarAward[index] = 1
	sysVar.AllDayChapterFlgNew = BaseFuc_serialize(TableHistory)
	AllDayGetInfo(sysarg, Label)
	--print("领取星奖励")
end

--购买特惠礼包
function AllDayBuyShop(sysarg, packet, idx)
	--[[
	------print("AllDayBuyShop")
	local Label = packet 
	if(type(packet) ~= 'number')then
		Label = DataPack.readByte(packet)
	end
	if(AllDayCfg[Label] == nil)then
		return
	end
	local TableHistory = CheckAllDayChapterData(sysarg, Label)	
	if(TableHistory[Label].Package[2] ~= nil)then	--领过奖励了
		return Actor.sendTipmsg( sysarg, Lang.ScriptTips.PathMonsterNest006, ttFlyTip )
	end	
	local SurplusTime = TableHistory[Label].Package[1] or  System.getCurrMiniTime()
	local SurplusCount = TableHistory[Label].Package[2] or 0
	if(SurplusTime == nil or 0 < SurplusCount)then	--没通关或者已领取
		return Actor.sendTipmsg( sysarg, Lang.ScriptTips.PathMonsterNest007, ttFlyTip )
	end	
	local cfg = AllDayCfg[Label].Package.Shop	
	if(SurplusTime + AllDayCfg[Label].Package.SurplusTime < System.getCurrMiniTime())then
		AllDayGetInfo(sysarg, Label)
		return ----print("time out")
	end
	--检查钱
	for k, v in pairs(cfg)do
		local nMoney = v.money
		local myMoney = Actor.getMoneyCount(sysarg, v.moneyType)
		if myMoney < nMoney then
			Actor.sendNotEnoughMoney(sysarg, v.moneyType, nMoney)
			return 
		end		
	end
	--检查背包空间
	if(Awards.CheckBagGridCount(sysarg, {cfg},1) ~= true) then 
		return 
	end	

	local sItem = Lang.LogTips.LogAllDay
	for k, v in pairs(cfg)do	--扣钱
		Actor.changeMoney(sysarg,v.moneyType, -v.money,LogIds.PathMonsterNestLogId,sItem)	--修改log
		local strItem = Item.getItemName(v.id)	
		if(v.quality ~=nil and 0 < v.quality)then
			local newItemPtr = Item.createItem(v.id,1,0,v.quality or 0,v.bind or 0 ,0, v.qualityDataIndex or 0)
			if newItemPtr == nil then
				return
			end	
			Item.addItem(sysarg,newItemPtr, sItem, LogIds.PathMonsterNestLogId,v.count)		--修改	
			strItem = Item.getItemLinkMsg(v.id,newItemPtr) 
		else	
			Actor.addItem(sysarg, v.id, v.quality or 0,0, v.count, v.bind or 0,0,sItem,292,v.qualityDataIndex or 0)	
		end			
	end
	TableHistory[Label].Package[2] = 1
	local sysVar = Actor.getStaticVar(sysarg)	
	sysVar.AllDayChapterFlgNew = BaseFuc_serialize(TableHistory)	
	AllDayGetInfo(sysarg, Label)
	--------print("购买特惠礼包")

	]]	
end

--领取宝箱 记得条件检测
function AllDayGetCheat(sysarg, packet, idx)
	--[[
	local Label = packet 
	local index = idx
	if(type(packet) ~= 'number')then
		Label = DataPack.readByte(packet)
		index = DataPack.readByte(packet)
	end
	if(AllDayCfg[Label] == nil or index == nil)then
		return
	end
	
	local TableHistory = CheckAllDayChapterData(sysarg, Label)	
	local flg = TableHistory[Label].Chest[index]
	--------print("Label,index", Label.." "..index)
	if(flg ~= nil)then	--领过奖励了
		return Actor.sendTipmsg( sysarg, Lang.ScriptTips.PathMonsterNest004, ttFlyTip )
	end
	local cfg = AllDayCfg[Label].Chest[index]
	if(cfg == nil)then
		return
	end
	if(0 < cfg.condition)then	--达到条件才能领取
		local startTime, completeCount, TableHistory, completeTime = CheckAllDayData(sysarg, Label, cfg.condition)
		if(completeTime == 0)then
			return
		end
	end	
	local awards = cfg.Award
	if(awards == nil)then
		return
	end
	local logId, logStr = LogIds.PathMonsterNestLogId, Lang.LogTips.LogAllDay	--修改
	if Awards.CheckBagGridCount(sysarg, awards) ~= true then
		return 
	end	
	Awards.Give(sysarg, awards, logId, logStr)
	local sysVar = Actor.getStaticVar(sysarg)	
	TableHistory[Label].Chest[index] = 1
	sysVar.AllDayChapterFlgNew = BaseFuc_serialize(TableHistory)		--AllDayChapterFlgNew
	AllDayGetInfo(sysarg, Label)
	--------print("领取宝箱")	
	]]
end

--刷怪
function AllDayCreateMonsters(sysarg, Label, idx)
	--StartEnterFb(sysarg, AllDayCfg[Label].FbId)
	local hScene = Actor.getSceneHandle(sysarg)

	--local sceneId = Actor.getSceneId(sysarg)
	--print("AllDayCreateMonsters sceneId = "..sceneId)

	local cfg = AllDayCfg[Label].Checkpoint[idx].Monsters
	for _, mon in ipairs(cfg or {}) do
		local num = Fuben.createMonstersInRange(hScene, mon.monsterId, mon.x1, mon.y1, mon.x2, mon.y2, mon.num, mon.livetime)
		--print("AllDayCreateMonsters num = "..num)
	end	
end

--获得某关数据并初始化数据
function CheckAllDayData(sysarg, Label, index, startTime)
	local bSave = false
	local sysVar = Actor.getStaticVar(sysarg)
	local TableHistory = {}
	if(sysVar.AllDayFlgNew ~= nil)then
		TableHistory = BaseFuc_unserialize(sysVar.AllDayFlgNew)
	end
	if type(TableHistory) ~= "table" then
		TableHistory = {}
	end
	if(TableHistory[Label] == nil)then
		TableHistory[Label] = {}
		bSave = true
	end
	if(TableHistory[Label][index] == nil)then
		TableHistory[Label][index] = {}
		bSave = true
	end
	if(TableHistory[Label][index].startTime == nil)then
		TableHistory[Label][index].startTime = 0
		bSave = true
	end
	if(TableHistory[Label][index].completeTime == nil)then
		TableHistory[Label][index].completeTime  = 0
		bSave = true
	end
	if(TableHistory[Label][index].completeCount == nil)then
		TableHistory[Label][index].completeCount = 0
		bSave = true
	end
	if(startTime ~= nil)then
		TableHistory[Label][index].startTime = startTime
		bSave = true
	end
	if(bSave == true)then
		sysVar.AllDayFlgNew = BaseFuc_serialize(TableHistory)	
	end
	--------print("startTime,Label,index",startTime.." "..Label.." "..index)
	--保存一个玩家进入副本临时的章第几关和开始时间，避免每次去判断
	if(startTime ~= nil)then
		local actorVar = Actor.getDyanmicVar(sysarg)
		if(actorVar.AllDayDyanmicVar == nil)then
			actorVar.AllDayDyanmicVar = {}
		end
		if actorVar.AllDayDonotChangeDVar == 1 then
		else
			actorVar.AllDayDyanmicVar[1] = Label
			actorVar.AllDayDyanmicVar[2] = index
			actorVar.AllDayDyanmicVar[3] = startTime
		end
	end	
	local startTime = TableHistory[Label][index].startTime
	local completeCount = TableHistory[Label][index].completeCount
	local completeTime = TableHistory[Label][index].completeTime
	return startTime, completeCount, TableHistory, completeTime
end


--保存副本通关时间并返回星
function SetAllDayTime(sysarg, Label, index)
	local sysVar = Actor.getStaticVar(sysarg)
	local startTime, completeCount, TableHistory = CheckAllDayData(sysarg, Label, index)
	local nowTime = System.getCurrMiniTime()
	local nTime = nowTime - startTime
	local OldTime = TableHistory[Label][index].completeTime
	if((nTime > 0 and nTime < OldTime) or OldTime <= 0 )then
		TableHistory[Label][index].completeTime = nTime
		sysVar.AllDayFlgNew = BaseFuc_serialize(TableHistory)
	end
	local bChapterSave = false
	if(#AllDayCfg[Label].Checkpoint <= index)then		--打完了最后一关，设置礼包倒计时
		local TableChapterHistory = CheckAllDayChapterData(sysarg, Label, System.getCurrMiniTime() )
	end
	----------print("OldTime,nTime",Label.." "..index.." "..OldTime.." "..nTime)
	--计算星并保存排行榜
	local star = 1
	for k,v in pairs(AllDayCfg[Label].Star)do
		if(0 < nTime and nTime <= v)then
			star = k
		end
	end	
	--print("startTime,nowTime,nTime",startTime.." "..nowTime.." "..nTime)
	return star, nTime
end

--保存副本次数
function SetAllDayCount(sysarg, Label, index, count )
	local nStarTime = System.getCurrMiniTime()
	local sysVar = Actor.getStaticVar(sysarg)
	local startTime, completeCount, TableHistory = CheckAllDayData(sysarg, Label, index)
	if count then
		TableHistory[Label][index].completeCount = completeCount + count
	else
		TableHistory[Label][index].completeCount = completeCount + 1
		TableHistory[Label][index].startTime = nStarTime	
	end
	sysVar.AllDayFlgNew = BaseFuc_serialize(TableHistory)	
end

--获得某章数据并初始化数据
function CheckAllDayChapterData(sysarg, Label, completeTime)
	local bSave = false
	local sysVar = Actor.getStaticVar(sysarg)
	local TableHistory = {}
	if(sysVar.AllDayChapterFlgNew ~= nil)then
		TableHistory = BaseFuc_unserialize(sysVar.AllDayChapterFlgNew)
	end		
	if(TableHistory[Label] == nil)then
		TableHistory[Label] = {}
		bSave = true
	end	
	if(TableHistory[Label].StarAward == nil)then	--累计星奖励
		TableHistory[Label].StarAward = {}
		bSave = true
	end	
	if(TableHistory[Label].Chest == nil)then		--过关宝箱奖励
		TableHistory[Label].Chest = {}
		bSave = true
	end	
	if(TableHistory[Label].Package == nil)then		--特惠礼包
		TableHistory[Label].Package = {}
		bSave = true
	end		
	if(completeTime ~= nil)then
		if(TableHistory[Label].Package[1] == nil or TableHistory[Label].Package[1] == 0)then
			TableHistory[Label].Package[1] = completeTime
			bSave = true
		end
	end
	if(bSave == true)then
		sysVar.AllDayChapterFlgNew = BaseFuc_serialize(TableHistory)	
	end	
	return TableHistory
end

function OpenAllDayRightPanel(sysarg, Label, index)
	local fubenPtr = Actor.getFubenPrt( sysarg )
	if(fubenPtr == nil)then
		return
	end
	local nStarTime = CheckAllDayData(sysarg, Label, index)
	if(AllDayCfg[Label] == nil)then
		return
	end
	local lastTime =  AllDayCfg[Label].Star[1] -( System.getCurrMiniTime() - nStarTime )
	
	local cfg = AllDayCfg[Label].Checkpoint[index].Monsters

	local panelType = 1
	local activityId = ACTIVITY_DEFINE_ALLDAY
	local panelInfo = {}
	panelInfo.subActivityId = Label
	panelInfo.sts = 1
	panelInfo.title = Lang.ScriptTips.PathMonsterNest010
	panelInfo.timeTitle = Lang.ScriptTips.PathMonsterNest011
	panelInfo.restTime = lastTime
	panelInfo.showStyle = 3
	--panelInfo.contentTitle = Lang.ScriptTips.PathMonsterNest012
	--panelInfo.contents = {}

	local handle = Actor.getSceneHandle(sysarg)

	-- for k,v in pairs(cfg)do
	-- 	local monName = MonsterNameDeleteNumber(v.monsterId)	
	-- 	local count = Fuben.getLiveMonsterCount(handle,v.monsterId) or 0	
	-- 	count = v.num - count
	-- 	table.insert(panelInfo.contents, string.format(Lang.ScriptTips.PathMonsterNest008,monName, count , v.num))
	-- end


	panelInfo.awardTitle = Lang.ScriptTips.PathMonsterNest013
	panelInfo.awards = AllDayCfg[Label].Checkpoint[index].ShowAward[1]

	--panelInfo.buttons = {1}

	OpenActivityRightPanel( sysarg, panelType, activityId, panelInfo )
end

function ChangeAllDayRightPanel(sysarg, Label, index)
	--print("ChangeAllDayRightPanel")
	local fubenPtr = Actor.getFubenPrt( sysarg )
	if(fubenPtr == nil)then
		return
	end
	local nStarTime = CheckAllDayData(sysarg, Label, index)
	
	if(AllDayCfg[Label] == nil)then
		return
	end
	local lastTime =  AllDayCfg[Label].Star[1] -( System.getCurrMiniTime() - nStarTime )
	
	local cfg = AllDayCfg[Label].Checkpoint[index].Monsters
	
	local handle = Actor.getSceneHandle(sysarg)

	panelInfo = {}
	-- panelInfo.contents = {}
	
	-- for k,v in pairs(cfg)do
	-- 	local monName = MonsterNameDeleteNumber(v.monsterId)
	-- 	local count = Fuben.getLiveMonsterCount(handle,v.monsterId) or 0	
	-- 	count = v.num - count
	-- 	--print("ChangeAllDayRightPanel count="..count)
	-- 	table.insert(panelInfo.contents, string.format(Lang.ScriptTips.PathMonsterNest008,monName, count , v.num))
	-- end
	
	panelInfo.sts = 2
	if(0 < Fuben.getLiveMonsterCount(handle,0))then
		panelInfo.sts = 1
	end

	--panelInfo.buttons = {1}

	ChangeActivityRightPanel( sysarg, panelInfo )
end

--获得怪物死亡的配置位置
function getAllDayFubenBossDie(monId)
	local Label = 1
	local index = 1
	for k,v in ipairs(AllDayCfg) do
		for j,tab in ipairs(v.Checkpoint) do
			for x,y in ipairs(tab.Monsters) do
				if(y.monsterId == monId)then
					Label = k
					index = j
					return Label, index
				end
			end
		end
	end	
	return Label,index
end

--通关 
function OnAllDayFubenBossDie(monster, sysarg, monId)
	--print("OnAllDayFubenBossDie monId = "..monId)

	--print("fubenId1 ="..Actor.getFubenId(sysarg))
	--print("getSceneId ="..Actor.getSceneId(sysarg))
	local AllDayState = false
	for iindex = 1, #AllDayCfg do
		for ii = 1, #AllDayCfg[iindex].Checkpoint do
			if Actor.getFubenId(sysarg) == AllDayCfg[iindex].Checkpoint[ii].FbId then
				--print("fubenId2 ="..AllDayCfg[iindex].Checkpoint[ii].FbId)
				if Actor.getSceneId(sysarg) == AllDayCfg[iindex].Checkpoint[ii].EnterPos[1] then
					--print("AllDayCfg[iindex].Checkpoint[1].EnterPos[1] =" ..AllDayCfg[iindex].Checkpoint[ii].EnterPos[1])
					AllDayState = true
					break
				end
			end
		end
	end
	if not AllDayState then
		return
	end
	--print("OnAllDayFubenBossDie ".." "..monId)
	local actorVar = Actor.getDyanmicVar(sysarg)
	if(actorVar.AllDayDyanmicVar == nil)then
		actorVar.AllDayDyanmicVar = {}
	end	
	local Label,index = actorVar.AllDayDyanmicVar[1], actorVar.AllDayDyanmicVar[2]--getAllDayFubenBossDie(monId)	
	ChangeAllDayRightPanel(sysarg, Label, index)
	local handle = Actor.getSceneHandle(sysarg)
	local count = Fuben.getLiveMonsterCount(handle,0) or 0 
	if(count == 0)then	--通关 
		--local actorId = Actor.getIntProperty( sysarg, PROP_ENTITY_ID )
		--local nValue = gRankMgr_GetValue(actorId, RANK_DEFINE_ALLDAY)
		local nStar, nTime = SetAllDayTime(sysarg, Label, index)
		actorVar.AllDayDyanmicVar[4] = nStar

		Actor.unregScriptCallback(sysarg, "AllDaySendCopyEnd")	
		AllDaySendCopyEnd(sysarg, Label, index, nStar, 1)

		--[[
		AllDayGetCrossAward(sysarg, Label, index, nStar)	
		AllDayGetInfo(sysarg, Label)
		]]
	end
end

--退出场景
function AllDayExit(sysarg)
	local fubenPtr 	= Actor.getFubenPrt(sysarg)
	if not fubenPtr then
		return
	end
	local fubenHandle = Fuben.getFubenHandle(fubenPtr)
	Fuben.setFubenTime( fubenHandle, 1 )

	Actor.exitFuben(sysarg)	
end

--退出场景
function OnAllDayExitHandle(sysarg)
	Actor.unregScriptCallback(sysarg, "AllDaySendCopyEnd")		
	CloseActivityRightPanel(sysarg)

	local actorVar = Actor.getDyanmicVar(sysarg)
	if(actorVar.AllDayDyanmicVar == nil)then
		actorVar.AllDayDyanmicVar = {}
	end	
	local Label = actorVar.AllDayDyanmicVar[1]
	local index = actorVar.AllDayDyanmicVar[2]
	local star = actorVar.AllDayDyanmicVar[4]
	--print("star ="..star)
	--print("Label ="..Label)
	--print("index ="..index)
	if Label and index and star then
		actorVar.AllDayDyanmicVar = nil

		AllDayGetCrossAward(sysarg, Label, index, star, 0)	
		AllDayGetInfo(sysarg, Label)
	end
end


--发送排行榜
function AllDaySendRank(sysarg)
	local rankLimit = AllDayCfg[1].rankLimit
	gRankMgr_SendToClient(sysarg, RANK_DEFINE_ALLDAY, 10, rankLimit, LogicCmd.activitySys.sysId, LogicCmd.activitySys.sub.sPathMonsterNestRank)
	--------print("发送排行榜")
end

--副本结束
function AllDaySendCopyEnd(sysarg, Label, index, nStar, bSucess)
	if(AllDayCfg[Label] == nil)then
		return
	end	
	Label = tonumber(Label)
	index = tonumber(index)
	nTime = tonumber(nTime)
	bSucess = tonumber(bSucess)
	local npack = DataPack.allocPacket(sysarg,LogicCmd.activitySys.sysId, LogicCmd.activitySys.sub.sPathMonsterNestOver)    
	if npack == nil then return end
	DataPack.writeByte(npack, Label)   	 
	DataPack.writeByte(npack, index)	
	DataPack.writeByte(npack, nStar)  
	DataPack.writeByte(npack, bSucess) 	
	DataPack.flush(npack)
	if(bSucess ==0)then
		AllDayExit(sysarg)	
	end
	------print("发送副本结束")
end

--清零每日副本完成次数
function ClearAllDayData(sysarg)
	local sysVar = Actor.getStaticVar(sysarg)
	local TableHistory = {}
	if(sysVar.AllDayFlgNew ~= nil)then
		TableHistory = BaseFuc_unserialize(sysVar.AllDayFlgNew)
	end	
	local bSave = false
	for k,v in pairs(TableHistory)do	
		for i,j in pairs(v)do
			if(j.completeCount ~= nil and j.completeCount ~= 0)then
				j.completeCount = 0
				bSave = true
			end
		end
	end
	if(bSave == true)then
		sysVar.AllDayFlgNew = BaseFuc_serialize(TableHistory)	
	end
end

-- http://192.168.0.175/Zgame/?srv=47&debug=true

function GMAllDayFuc(sysarg, arg1, arg2)
	------print("GMAllDayFuc")
	if(arg1 == 1)then		--进入副本
		return AllDayEnterScene(sysarg, 1, 1)	-- @DebugLua 2001 1 0
	end
	if(arg1 == 2)then		--获取副本信息
		return AllDayGetInfo(sysarg, 1, 1)		-- @DebugLua 2001 2 0
	end	
	if(arg1 == 3)then
		return AllDayGetAward(sysarg,1, 1)		-- @DebugLua 2001 3 0
	end
	if(arg1 == 4)then
		return AllDayBuyShop(sysarg, 1, 1)		-- @DebugLua 2001 4 0
	end
	if(arg1 == 5)then
		return AllDayGetCheat(sysarg, 1, 1)		-- @DebugLua 2001 5 0
	end
	if(arg1 == 6)then
		return AllDaySendRank(sysarg, 1, 1)		-- @DebugLua 2001 6 0
	end	
end

function AllDayClearMonsters(sysarg)
	local pScene = Actor.getScenePtr(sysarg)
	Fuben.clearSceneAllMonsters(pScene)
	OnAllDayFubenBossDie(nil, sysarg, nil)
end

function AllDayFail(sysarg)
	local actorVar = Actor.getDyanmicVar(sysarg)
	if(actorVar.AllDayDyanmicVar == nil)then
		actorVar.AllDayDyanmicVar = {}
	end	
	local Label,index = actorVar.AllDayDyanmicVar[1], actorVar.AllDayDyanmicVar[2]
	AllDaySendCopyEnd(sysarg, Label, index, 0, 0)
end


function AllDayFinishHandler(sysarg)
	local num = Fuben.getMonsterNum(sysarg)
	if num > 0 then
		AllDayFail(sysarg)
	else
		local actorVar = Actor.getDyanmicVar(sysarg)
		if(actorVar.AllDayDyanmicVar == nil)then
			actorVar.AllDayDyanmicVar = {}
		end
		local Label = actorVar.AllDayDyanmicVar[1]
		local index = actorVar.AllDayDyanmicVar[2]
		local nStar = actorVar.AllDayDyanmicVar[4]

		AllDayGetCrossAward(sysarg, Label, index, nStar, 0)

		local fubenPtr 	= Actor.getFubenPrt(sysarg)
		if not fubenPtr then
			return
		end
		local fubenHandle = Fuben.getFubenHandle(fubenPtr)
		Fuben.setFubenTime( fubenHandle, 1 )

		Actor.exitFuben(sysarg) 
		Actor.openDialogs(sysarg, enLinkPathMonsterNest)
	end
end

function OnAllDayLogout(sysarg)
	local num = Fuben.getMonsterNum(sysarg)
	local actorVar = Actor.getDyanmicVar(sysarg)
	if(actorVar.AllDayDyanmicVar == nil)then
		actorVar.AllDayDyanmicVar = {}
	end	
	if num > 0 then
		DroplineSaveFubenHandler(sysarg)
		local sVar = Actor.getStaticVar(sysarg)
		if(sVar.AllDayDyanmicVar == nil)then
			sVar.AllDayDyanmicVar = {}
		end	
		
		sVar.AllDayDyanmicVar[1] = actorVar.AllDayDyanmicVar[1]
		sVar.AllDayDyanmicVar[2] = actorVar.AllDayDyanmicVar[2]
	else
		local Label = actorVar.AllDayDyanmicVar[1]
		local index = actorVar.AllDayDyanmicVar[2]
		local nStar = actorVar.AllDayDyanmicVar[4]
		if Label and index then
			if not nStar then
				nStar = SetAllDayTime(sysarg, Label, index)
			end
			AllDayGetCrossAward(sysarg, Label, index, nStar, 0)
		end

		local fubenPtr 	= Actor.getFubenPrt(sysarg)
		if not fubenPtr then
			return
		end
		local fubenHandle = Fuben.getFubenHandle(fubenPtr)
		Fuben.setFubenTime( fubenHandle, 1 )
	end
end

function OnAllDayLogin(sysarg, fubenPtr)
	local fubenHandle = Fuben.getFubenHandle(fubenPtr)
	if fubenHandle then
		Actor.enterFuBen(sysarg, fubenHandle, -1, -1, -1)
		local sVar = Actor.getStaticVar(sysarg)
		if(sVar.AllDayDyanmicVar == nil)then
			sVar.AllDayDyanmicVar = {}
		end	
		local Label,index = sVar.AllDayDyanmicVar[1], sVar.AllDayDyanmicVar[2]
		local actorVar = Actor.getDyanmicVar(sysarg)
		if(actorVar.AllDayDyanmicVar == nil)then
			actorVar.AllDayDyanmicVar = {}
		end	
		actorVar.AllDayDyanmicVar[1] = sVar.AllDayDyanmicVar[1]
		actorVar.AllDayDyanmicVar[2] = sVar.AllDayDyanmicVar[2]
		actorVar.AllDayDonotChangeDVar = 1
		sVar.AllDayDyanmicVar[1] = nil
		sVar.AllDayDyanmicVar[2] = nil
		if Actor.getFubenId(sysarg) ~= 0 then
			OpenAllDayRightPanel(sysarg, Label, index)

			local nStarTime = CheckAllDayData(sysarg, Label, index)
			if(AllDayCfg[Label] == nil)then
				return
			end
			local lastTime =  AllDayCfg[Label].Star[1] -( System.getCurrMiniTime() - nStarTime )
			Actor.unregScriptCallback(sysarg, "AllDaySendCopyEnd")	
			Actor.regScriptTimer(sysarg, 0, lastTime*1000, lastTime*1000 , 1, "AllDaySendCopyEnd",Label,index,0,0)
		end
	end
end

function InitAllDay()
    local len = #AllDayCfg
	for idx = 1, len do
		local len2 = #AllDayCfg[idx].Checkpoint
		for ii = 1, len2 do
			SceneExitDispatcher.register( AllDayCfg[idx].Checkpoint[ii].EnterPos[1], OnAllDayExitHandle )	

            SceneLogoutDispatcher.register( AllDayCfg[idx].Checkpoint[ii].EnterPos[1], OnAllDayLogout )  

            FubenTimeoutDispatcher.register( AllDayCfg[idx].Checkpoint[ii].FbId, OnAllDayTimeout )
		end
	end
end

--[[
材料副本时间到,会被自动踢出副本
]]
function OnAllDayTimeout( fubenPtr )
	local actorList = LuaHelp.getFbActorList(fubenPtr)
    for k, sysarg in ipairs( actorList or {} ) do
	   	local num = Fuben.getMonsterNum(sysarg)
	   	local actorVar = Actor.getDyanmicVar(sysarg)
		if(actorVar.AllDayDyanmicVar == nil)then
			actorVar.AllDayDyanmicVar = {}
		end	
		if num > 0 then
			DroplineSaveFubenHandler(sysarg)
			local sVar = Actor.getStaticVar(sysarg)
			if(sVar.AllDayDyanmicVar == nil)then
				sVar.AllDayDyanmicVar = {}
			end	
			sVar.AllDayDyanmicVar[1] = actorVar.AllDayDyanmicVar[1]
			sVar.AllDayDyanmicVar[2] = actorVar.AllDayDyanmicVar[2]
		else
			local Label = actorVar.AllDayDyanmicVar[1]
			local index = actorVar.AllDayDyanmicVar[2]
			local nStar = actorVar.AllDayDyanmicVar[4]
			if Label and index then
				if not nStar then
					nStar = SetAllDayTime(sysarg, Label, index)
				end
				AllDayGetCrossAward(sysarg, Label, index, nStar, 0)
			end

			local fubenPtr 	= Actor.getFubenPrt(sysarg)
			if not fubenPtr then
				return
			end
			local fubenHandle = Fuben.getFubenHandle(fubenPtr)
			Fuben.setFubenTime( fubenHandle, 1 )
		end 
    end
end

--旧数据转化
function AllDayLoginOldDataToNewData(sysarg)
	local sysVar = Actor.getStaticVar(sysarg)
	if sysVar.allDayOldDataToNewData then
		return
	end
	sysVar.allDayOldDataToNewData = 1
	local TableHistory = {}
	if(sysVar.AllDayFlgNew ~= nil)then
		TableHistory = BaseFuc_unserialize(sysVar.AllDayFlgNew)
	end
	local len = #AllDayCfg
	for idx = 1, len do
		local len2 = #AllDayCfg[idx].Checkpoint
		for ii = 1, len2 do
			local Label = (idx - 1) * 5 + ii
			local startTimeOld, completeCountOld, completeTimeOld = CheckAllDayDataOld(sysarg, Label, 5)

			if type(TableHistory) ~= "table" then
				TableHistory = {}
			end
			if(TableHistory[idx] == nil)then
				TableHistory[idx] = {}
			end
			if(TableHistory[idx][ii] == nil)then
				TableHistory[idx][ii] = {}
			end
			if(completeTimeOld ~= nil)then
				TableHistory[idx][ii].completeTime  = completeTimeOld
			end
			if(completeCountOld ~= nil)then
				TableHistory[idx][ii].completeCount = completeCountOld
			end
			if(startTimeOld ~= nil)then
				TableHistory[idx][ii].startTime = startTimeOld
			end
		end
	end
	sysVar.AllDayFlgNew = BaseFuc_serialize(TableHistory)	
end

--获得某关数据并初始化数据
function CheckAllDayDataOld(sysarg, Label, index, startTime)
	local sysVar = Actor.getStaticVar(sysarg)
	local TableHistory = {}
	if(sysVar.AllDayFlg ~= nil)then
		TableHistory = BaseFuc_unserialize(sysVar.AllDayFlg)
	end
	if type(TableHistory) ~= "table" then
		TableHistory = {}
	end
	if(TableHistory[Label] == nil)then
		TableHistory[Label] = {}
	end
	if(TableHistory[Label][index] == nil)then
		TableHistory[Label][index] = {}
	end
	local startTime = TableHistory[Label][index].startTime
	local completeCount = TableHistory[Label][index].completeCount
	local completeTime = TableHistory[Label][index].completeTime
	return startTime, completeCount, completeTime
end

--[[
--获得某章数据并初始化数据
function CheckAllDayChapterData(sysarg, Label, completeTime)
	local bSave = false
	local sysVar = Actor.getStaticVar(sysarg)
	local TableHistory = {}
	if(sysVar.AllDayChapterFlg ~= nil)then
		TableHistory = BaseFuc_unserialize(sysVar.AllDayChapterFlg)
	end		
	if(TableHistory[Label] == nil)then
		TableHistory[Label] = {}
		bSave = true
	end	
	if(TableHistory[Label].StarAward == nil)then	--累计星奖励
		TableHistory[Label].StarAward = {}
		bSave = true
	end	
	if(TableHistory[Label].Chest == nil)then		--过关宝箱奖励
		TableHistory[Label].Chest = {}
		bSave = true
	end	
	if(TableHistory[Label].Package == nil)then		--特惠礼包
		TableHistory[Label].Package = {}
		bSave = true
	end		
	if(completeTime ~= nil)then
		if(TableHistory[Label].Package[1] == nil or TableHistory[Label].Package[1] == 0)then
			TableHistory[Label].Package[1] = completeTime
			bSave = true
		end
	end
	if(bSave == true)then
		sysVar.AllDayChapterFlg = BaseFuc_serialize(TableHistory)	
	end	
	return TableHistory
end

]]